<?php
// @formatter:off
/**
 * @file s.editname.php
 * @author Alejandro Dario Simi
 * @date $Date: 2013-06-16 23:56:49 +0000 (Sun, 16 Jun 2013) $
 *
 * $Id: s.editname.php 73 2013-06-16 23:56:49Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/tags/wcomix-1.0/themes/default/controlers/simplecontainer/s.editname.php $
 */
// @formatter:on

global $wcGroupForbidden;
global $wcComic;
global $wcDirectory;
global $wcTag;
global $wcCollection;
global $wcRule;
global $wcThemeAssigns;

if(defined('__SIMPLE_CONTAINER__') && !$wcGroupForbidden && $wcProfile->allowedAny(WC_PERM_COMIC_RENAME, WC_PERM_DIRECTORY_RENAME, WC_PERM_TAG_RENAME, WC_PERM_COLLECTION_RENAME, WC_PERM_RULE_RENAME)) {
	$wcThemeAssigns['ACTIONCONTENT'] = "/simplecontainer/s.editname.html";

	if($wcComic && $wcProfile->granted(WC_PERM_COMIC_RENAME)) {
		$name = explode(".", $wcComic->next_name ? $wcComic->next_name : $wcComic->name);
		array_pop($name);
		$name = implode(".", $name);

		$wcThemeAssigns['EDIT-WHAT'] = "comic";
		$wcThemeAssigns['EDIT-NAME'] = $name;
		$wcThemeAssigns['EDIT-ID'] = $wcComic->id;
		$wcThemeAssigns['EDIT-URI-NAME'] = "comic";
		$wcThemeAssigns['EDIT-PREVIEWS'] = array($wcComic->previewUri());
		$wcThemeAssigns['EDIT-SERVICE'] = WC_SERVICE_COMICS;
	} elseif($wcDirectory && $wcProfile->granted(WC_PERM_DIRECTORY_RENAME)) {
		$wcThemeAssigns['EDIT-WHAT'] = "directory";
		$wcThemeAssigns['EDIT-NAME'] = $wcDirectory->next_name ? $wcDirectory->next_name : $wcDirectory->name;
		$wcThemeAssigns['EDIT-ID'] = $wcDirectory->id;
		$wcThemeAssigns['EDIT-URI-NAME'] = "directory";
		$wcThemeAssigns['EDIT-PREVIEWS'] = array_slice($wcDirectory->previews(), 0, 4);
		$wcThemeAssigns['EDIT-SERVICE'] = WC_SERVICE_DIRECTORIES;
	} elseif($wcTag && $wcProfile->granted(WC_PERM_TAG_RENAME)) {
		$wcThemeAssigns['EDIT-WHAT'] = "tag";
		$wcThemeAssigns['EDIT-NAME'] = $wcTag->name;
		$wcThemeAssigns['EDIT-ID'] = $wcTag->id;
		$wcThemeAssigns['EDIT-URI-NAME'] = "tag";
		$wcThemeAssigns['EDIT-PREVIEWS'] = array_slice($wcTag->previews(), 0, 4);
		$wcThemeAssigns['EDIT-SERVICE'] = WC_SERVICE_TAGS;
	} elseif($wcCollection && $wcProfile->granted(WC_PERM_COLLECTION_RENAME)) {
		$wcThemeAssigns['EDIT-WHAT'] = "collection";
		$wcThemeAssigns['EDIT-NAME'] = $wcCollection->name;
		$wcThemeAssigns['EDIT-ID'] = $wcCollection->id;
		$wcThemeAssigns['EDIT-URI-NAME'] = "collection";
		$wcThemeAssigns['EDIT-PREVIEWS'] = array_slice($wcCollection->previews(), 0, 4);
		$wcThemeAssigns['EDIT-SERVICE'] = WC_SERVICE_COLLECTIONS;
	} elseif($wcRule && $wcProfile->granted(WC_PERM_RULE_RENAME)) {
		global $wcTheme;

		$wcThemeAssigns['EDIT-WHAT'] = "rule";
		$wcThemeAssigns['EDIT-NAME'] = $wcRule->name;
		$wcThemeAssigns['EDIT-ID'] = $wcRule->id;
		$wcThemeAssigns['EDIT-URI-NAME'] = "rule";
		$wcThemeAssigns['EDIT-PREVIEWS'] = array(WCSanitizer::WComixPath("{$this->_themeUri}/icons/rules-icon-128px.png"));
		//$wcRule->previews();
		$wcThemeAssigns['EDIT-SERVICE'] = WC_SERVICE_RULES;
	} else {
		$wcThemeAssigns["error-string"] = "This item is not available for name edition";
		require "{$this->_themeRoot}/controlers/contents/c.500.php";
	}
} else {
	$wcThemeAssigns["error-string"] = "You're not allowed to edit item's name";
	require "{$this->_themeRoot}/controlers/contents/c.403.php";
}
?>